Skip to content

REF: Apply.apply_multiple #53362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 25, 2023

Conversation

topper-123
Copy link
Contributor

A step towards fixing #53325 (comment).

This avoids the need to call out into (Series|DataFrame).aggregate. In a follow-up I will replace the use of agg_(list|dict)_like with apply specific versions of those methds or some similar solution, avoiding needing to call Apply.agg from within Apply.apply_multiple.

CC @rhshadrach

@@ -554,7 +561,20 @@ def apply_multiple(self) -> DataFrame | Series:
result: Series, DataFrame, or None
Result when self.f is a list-like or dict-like, None otherwise.
"""
return self.obj.aggregate(self.f, self.axis, *self.args, **self.kwargs)
if self.axis == 1 and isinstance(self.obj, ABCDataFrame):
return self.obj.T.apply(self.f, 0, *self.args, **self.kwargs).T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be args=self.args, not *self.args. Can you add a test here?

Copy link
Contributor Author

@topper-123 topper-123 May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good catch. Done.

@mroeschke mroeschke added the Apply Apply, Aggregate, Transform, Map label May 24, 2023
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rhshadrach rhshadrach added the Refactor Internal refactoring of code label May 25, 2023
@rhshadrach rhshadrach added this to the 2.1 milestone May 25, 2023
@rhshadrach rhshadrach merged commit 8bdc304 into pandas-dev:main May 25, 2023
@topper-123 topper-123 deleted the ref_Apply.apply_multiple branch May 25, 2023 05:50
topper-123 added a commit to topper-123/pandas that referenced this pull request May 27, 2023
topper-123 added a commit to topper-123/pandas that referenced this pull request Jun 5, 2023
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants